<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>xeokit Example</title>
    <link href="../css/pageStyle.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
    <style>
        #myCanvas {
            width: 100%;
            height: 100%;
            background: lightBlue;
        }

        .annotation-marker {
            color: #ffffff;
            line-height: 1.8;
            text-align: center;
            font-family: "monospace";
            font-weight: bold;
            position: absolute;
            width: 25px;
            height: 25px;
            border-radius: 15px;
            border: 2px solid #ffffff;
            background: black;
            visibility: hidden;
            box-shadow: 5px 5px 15px 1px #000000;
            z-index: 0;
        }

        .annotation-label {
            position: absolute;
            max-width: 250px;
            min-height: 50px;
            padding: 8px;
            padding-left: 12px;
            padding-right: 12px;
            background: #ffffff;
            color: #000000;
            -webkit-border-radius: 3px;
            -moz-border-radius: 3px;
            border-radius: 8px;
            border: #ffffff solid 2px;
            box-shadow: 5px 5px 15px 1px #000000;
            z-index: 90000;
        }

        .annotation-label:after {
            content: '';
            position: absolute;
            border-style: solid;
            border-width: 8px 12px 8px 0;
            border-color: transparent white;
            display: block;
            width: 0;
            z-index: 1;
            margin-top: -11px;
            left: -12px;
            top: 20px;
        }

        .annotation-label:before {
            content: '';
            position: absolute;
            border-style: solid;
            border-width: 9px 13px 9px 0;
            border-color: transparent #ffffff;
            display: block;
            width: 0;
            z-index: 0;
            margin-top: -12px;
            left: -15px;
            top: 20px;
        }

        .annotation-title {
            font: normal 20px arial, serif;
            margin-bottom: 8px;
        }

        .annotation-desc {
            font: normal 14px arial, serif;
        }

    </style>

</head>
<body>
<input type="checkbox" id="info-button"/>
<label for="info-button" class="info-button"><i class="far fa-3x fa-question-circle"></i></label>
<canvas id="myCanvas"></canvas>
<div class="slideout-sidebar">
    <img class="info-icon" src="../../assets/images/bim_icon.png"/>
    <h1>XKTLoaderPlugin</h1>
    <h2>Full-precision BIM model with annotations</h2>
    <p>In this example, we're loading a double-precision BIM model, which xeokit renders using double-precision
        emulation. This eliminates "rounding jitter" while rendering.</p>
    <p>After the model has loaded, we then programmatically attach some annotations to it.</p>
    <ul>
        <li>Model center is [1842022, 10, -5173301]</li>
    </ul>
    <h3>Components Used</h3>
    <ul>
        <li>
            <a href="../../docs/class/src/viewer/Viewer.js~Viewer.html"
               target="_other">Viewer</a>
        </li>
        <li>
            <a href="../../docs/class/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js~XKTLoaderPlugin.html"
               target="_other">XKTLoaderPlugin</a>

        </li>
        <li>
            <a href="../../docs/class/src/plugins/AnnotationsPlugin/AnnotationsPlugin.js~AnnotationsPlugin.html"
               target="_other">AnnotationsPlugin</a>
        </li>
    </ul>
    <h3>Resources</h3>
    <ul>
        <li><a href="https://www.notion.so/xeokit/Viewing-Double-Precision-Models-3f9e155fd1394d1f974474484decf31b"
               target="_other">Tutorial</a></li>
        <li>Model provided by <a href="https://bimdata.io" target="_other">BIMData.io</a></li>
    </ul>
</div>
</body>
<script type="module">

    //------------------------------------------------------------------------------------------------------------------
    // Import the modules we need for this example
    //------------------------------------------------------------------------------------------------------------------

    import {Viewer, XKTLoaderPlugin, AnnotationsPlugin} from "../../dist/xeokit-sdk.min.es.js";

    //------------------------------------------------------------------------------------------------------------------
    // Create a Viewer, arrange the camera
    //------------------------------------------------------------------------------------------------------------------

    const viewer = new Viewer({
        canvasId: "myCanvas",
        transparent: true,
        dtxEnabled: true
    });

    viewer.scene.camera.eye = [1841982.5187600704, 19.207790938410042, -5173303.042326414];
    viewer.scene.camera.look = [1842011.793756829, 9.913817421536704, -5173299.841616623];
    viewer.scene.camera.up = [0.2991762376746394, 0.9536370664170352, 0.0327096983532173];

    viewer.cameraControl.followPointer = true;

    const scene = viewer.scene;
    const sao = scene.sao;
    // sao.enabled = true;

    //----------------------------------------------------------------------------------------------------------------------
    // Create a xeokit loader plugin, load a model, fit to view
    //----------------------------------------------------------------------------------------------------------------------

    const xktLoader = new XKTLoaderPlugin(viewer);

    const model1 = xktLoader.load({
        id: "myModel1",
        src: "../../assets/models/xkt/v7/MAP/MAP.xkt",
        metaModelSrc: "../../assets/models/xkt/v7/MAP/MAP.json",
        edges: true,
        excludeTypes: ["IfcSpace"],
        objectDefaults: {}
    });

    //------------------------------------------------------------------------------------------------------------------
    // When the model has loaded, create some annotations
    //------------------------------------------------------------------------------------------------------------------

    const annotations = new AnnotationsPlugin(viewer, {
        markerHTML: "<div class='annotation-marker' style='background-color: {{markerBGColor}};'>{{glyph}}</div>",
        labelHTML: "<div class='annotation-label' style='background-color: {{labelBGColor}};'><div class='annotation-title'>{{title}}</div><div class='annotation-desc'>{{description}}</div></div>",
        values: {
            markerBGColor: "red",
            glyph: "X",
            title: "Untitled",
            description: "No description"
        },
        surfaceOffset: 0.75
    });

    annotations.on("markerClicked", (annotation) => {
        annotation.labelShown = !annotation.labelShown;
    });

    model1.on("loaded", () => {
        viewer.cameraFlight.jumpTo(model1);

        viewer.scene.on("tick", () => {
            viewer.scene.camera.orbitYaw(1.0);
        });

        annotations.createAnnotation({
            id: "a1",
            worldPos: [1842036.164901515, 2.2709207218137575, -5173304.935329479],
            occludable: true,
            markerShown: true,
            labelShown: true,
            values: {
                glyph: "A1",
                title: "My annotation 1",
                description: "My description 1"
            },
        });

        annotations.createAnnotation({
            id: "a2",
            worldPos: [1842016.7502089352, 16.116118310916697, -5173304.496801555],
            occludable: true,
            markerShown: true,
            labelShown: true,
            values: {
                glyph: "A2",
                title: "My annotation 2",
                description: "My description 2"
            },
        });

        annotations.createAnnotation({
            id: "a3",
            worldPos: [1842009.1252660889, 0.22266775344006823, -5173293.303721189],
            occludable: true,
            markerShown: true,
            labelShown: true,
            values: {
                glyph: "A3",
                title: "My annotation 3",
                description: "My description 3"
            },
        });

        annotations.createAnnotation({
            id: "a4",
            worldPos: [1842021.0555786698, 22.064205794296942, -5173293.94533045],
            occludable: true,
            markerShown: true,
            labelShown: true,
            values: {
                glyph: "A4",
                title: "My annotation 4",
                description: "My description 4"
            },
        });

    });

</script>
</html>